/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Displayable;
import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;
import sg.edu.nus.iss.pacman.dao.Maze;
/**
 *
 * @author daniel
 */
public class ViewMapHighScore extends List implements CommandListener
{
    private static final String TITLE = "Select Map";
    private Command cmdSelect, cmdBack;
    private PacManMIDlet mainApp;
    private Maze[] listMaze;

    public ViewMapHighScore(PacManMIDlet mainApp, Maze[] listMaze)
    {
        super(TITLE, List.IMPLICIT, new String[]{}, null);
        this.mainApp = mainApp;
        this.listMaze = listMaze;
        init();
    }

    void init()
    {
        cmdSelect = new Command(PacManMIDlet.LABEL_CMD_SELECT, Command.OK, 1);
        cmdBack = new Command(PacManMIDlet.LABEL_CMD_BACK, Command.BACK, 1);

        for (int i=0; i<listMaze.length; i++) {
			Maze maze = listMaze[i];
			insert(i, maze.getMazeName(), null);
		}

        addCommand(cmdSelect);
        addCommand(cmdBack);
        setCommandListener(this);

    }

    public void commandAction(Command c, Displayable d)
    {
        if (cmdBack == c)
        {
            mainApp.displayMainMenu();
        }
        else if (cmdSelect == c)
        {
            int idx = getSelectedIndex();
            if (idx >= 0)
            {
                mainApp.displayHighScoresList(listMaze[idx].getMazeName());
            }
        }
    }
}
